package com.patrol.logisticsmanage.common;

import android.annotation.SuppressLint;
import android.text.Editable;
import android.text.InputFilter;
import android.text.Spanned;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.patrol.logisticsmanage.ui.canteen.utils.LogUtils;

import java.util.HashMap;
import java.util.Map;

public class InputFilterMinMax{
    public static void setRegin(EditText editText,int min, int max){
        editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean hasFocus) {
                if (hasFocus) {     // 得到焦点
                    if((editText.getText()==null) ||
                            ("".equals(editText.getText().toString()))){
                        editText.setText("" +min); //默认设置为1
                    }else{

                    }
                } else {            // 失去焦点
                    if((editText.getText()==null) ||
                            ("".equals(editText.getText().toString()))){
                        editText.setText("" + min);//默认设置为1
                    }else{
                        double val = Double.parseDouble(editText.getText().toString());
                        if(val<min){
                            editText.setText("" + min);
                        }else if(val > max){
                            editText.setText("" + max);
                        }

                    }
                }
            }

        });
    }

}